#include "../../Header/Header.h"
#include "ResourceManagement.h"
#include "TextureEx.h"

ResourceManagement* ResourceManagement::m_bInstance = 0;

ResourceManagement::ResourceManagement()
: m_ShaderBank(0), m_MeshBank(0), m_TextureBank(0),
m_AudioBank(0), m_VideoBank(0),
m_MaterialBank(0), m_EffectBank(0)
{

}

ResourceManagement::~ResourceManagement()
{
	SAFE_DEL(m_ShaderBank);
	SAFE_DEL(m_MeshBank);
	SAFE_DEL(m_TextureBank);
	SAFE_DEL(m_VideoBank);
	SAFE_DEL(m_AudioBank);
	SAFE_DEL(m_MaterialBank);
	SAFE_DEL(m_EffectBank);
}

void ResourceManagement::Init(char* strFileSpect)
{
	m_MeshBank = new ResourceBank();
	m_TextureBank = new ResourceBank();
}

void ResourceManagement::Load()
{
	/*int texCount = 5;
	char **aszFile = new char*[texCount];
	aszFile[0] = "../Resources/Textures/Blend.tga";
	aszFile[1] = "../Resources/Textures/Grass.tga";
	aszFile[2] = "../Resources/Textures/Dirt.tga";
	aszFile[3] = "../Resources/Textures/Rock.tga";
	aszFile[4] = "../Resources/Textures/Water.tga";
	TextureEx* terrainTexture = new TextureEx();
	terrainTexture->Init2D(aszFile, texCount);
	SAFE_DEL_ARRAY(aszFile);
	terrainTexture->Load();
	this->Add(RESOURCE_TEXTURE, terrainTexture);*/

}

void ResourceManagement::Add(RESOURCE_TYPE type, Resource* element)
{
	switch (type)
	{
	case RESOURCE_MESH:
	{
						  if (m_MeshBank)
						  {
							  m_MeshBank->Add(element);
						  }
	}
		break;
	case RESOURCE_TEXTURE:
	{
							 if (m_TextureBank)
							 {
								 m_TextureBank->Add(element);
							 }
	}
		break;
	default:
		break;
	}
}

Resource* ResourceManagement::Reference(RESOURCE_TYPE type, int index)
{
	switch (type)
	{
	case RESOURCE_MESH:
	{
						  if (m_MeshBank)
						  {
							  return m_MeshBank->Reference(index);
						  }
						  return 0;
	}
		break;
	case RESOURCE_TEXTURE:
	{
							 if (m_TextureBank)
							 {
								return m_TextureBank->Reference(index);
							 }
	}
		break;
	default:
		break;
	}
}

void ResourceManagement::Dereference(RESOURCE_TYPE type, int index)
{
	switch (type)
	{
	case RESOURCE_MESH:
	{
						  if (m_MeshBank)
						  {
							  m_MeshBank->Dereference(index);
						  }
	}
		break;
	case RESOURCE_TEXTURE:
	{
							 if (m_TextureBank)
							 {
								 m_TextureBank->Dereference(index);
							 }
	}
		break;
	default:
		break;
	}
}